package com.cryptoneedle.garden.repository.source.constraint;


import com.bubbles.engine.data.core.repository.BaseRepository;
import com.cryptoneedle.garden.entity.source.constraint.SourceIndexUnique;
import com.cryptoneedle.garden.key.source.constraint.IndexKey;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>description: 源数据源-唯一索引 </p>
 *
 * @author CryptoNeedle
 * @date 2025-06-20
 */
@Repository
public interface SourceIndexUniqueRepository extends BaseRepository<SourceIndexUnique, IndexKey> {

    @Query("  FROM SourceIndexUnique " +
            "WHERE catalogName = :catalogName " +
            "ORDER BY catalogName, databaseName, tableName, indexName, position")
    List<SourceIndexUnique> indexUniques(String catalogName);

    @Query("  FROM SourceIndexUnique " +
            "WHERE catalogName = :catalogName " +
            "  AND databaseName = :databaseName " +
            "ORDER BY catalogName, databaseName, tableName, indexName, position")
    List<SourceIndexUnique> indexUniques(String catalogName, String databaseName);

    @Query("  FROM SourceIndexUnique " +
            "WHERE catalogName = :catalogName " +
            "  AND databaseName = :databaseName " +
            "  AND tableName = :tableName " +
            "ORDER BY catalogName, databaseName, tableName, indexName, position")
    List<SourceIndexUnique> indexUniques(String catalogName, String databaseName, String tableName);

    @Query("  FROM SourceIndexUnique " +
            "WHERE catalogName = :catalogName " +
            "  AND databaseName = :databaseName " +
            "  AND tableName = :tableName " +
            "  AND columnName = :columnName " +
            "ORDER BY catalogName, databaseName, tableName, indexName, position")
    List<SourceIndexUnique> indexUniques(String catalogName, String databaseName, String tableName, String columnName);
}